const state = {
	wxappid: 'wx3f4d29ad53d2bfa9',

	open_id: '',
	sessionKey: '',
	token: '',
	uid: '',
	role: 0, //角色:1=普通用户，2=会员，，9=店长，
	create_time: '', // 加入时间

	nickname: '',
	avatar_url: '',
	birthday: '',
	gender: '', //0='男',1='女'
	mobile: '',
	country: '', // 国家
	province: '', // 省份
	city: '', // 城市
	district: '', // 区（县）
	street: '', // 街道信息
	streetNum: '', // 门牌号
}

const getters = {
	getLoginInfo(state) {
		return state;
	}
}

const mutations = {
	setLoginInfo(state, payload) {
		Object.keys(payload).forEach((key) => {
			if (payload[key]) {
				state[key] = payload[key];
			}
		});
		uni.setStorageSync('login', state);
	},
	clearLoginInfo(state) {
		console.log("clearLoginInfo");
		Object.keys(state).forEach((key) => {
			const type_of = typeof(state[key]);
			switch (type_of) {
				case 'string':
					state[key] = '';
					break;
				case 'number':
					state[key] = 0;
					break;
				default:
					state[key] = undefined;
					break;
			}
		});

		uni.setStorageSync('login', state);
	},
}

export default {
	namespaced: true, // 开启namespace:true，该模块就成为命名空间模块了
	state,
	getters,
	mutations,
}